package com.bgs.eat.userProtal.controller;

import com.bgs.eat.config.CommonResult;
import com.bgs.eat.page.PageRequest;
import com.bgs.eat.page.PageResult;
import com.bgs.eat.userProtal.entity.UserProtalEntity;
import com.bgs.eat.userProtal.service.UserProtalService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @ClassName UserProtalController
 * @Description TODO
 * @Author hbx
 * @Date 2022/10/11 14:43
 **/
@RestController
@RequestMapping("userProtal")
@CrossOrigin
public class UserProtalController {

    @Autowired
    UserProtalService userProtalService;

    /**
    * @Author hbx
    * @Description 根据审批id查询用户信息 (后端审批管理) 骑手审批管理
    * @Date 2022/10/14 11:22
    * @param pageRequest
    * @param userName
    */
    @GetMapping("/getUserProtalByAudit")
    public PageResult getUserProtalByAudit(PageRequest pageRequest, String userName){
        return userProtalService.getUserProtalByAudit(pageRequest,userName);
    }

    /**
    * @Author cjl
    * @Description 根据审批id查询用户信息 (后端审批管理) 商家审批管理
    * @Date  10:23
    * @Return com.bgs.eat.page.PageResult
    * @param pageRequest
    * @param userName
    */
    @GetMapping("/getUserProtalByAuditMerchant")
    public PageResult getUserProtalByAuditMerchant(PageRequest pageRequest, String userName){
        return userProtalService.getUserProtalByAuditMerchant(pageRequest,userName);
    }

    /**
    * @Author hbx
    * @Description 修改用户账号名称信息
    * @Date 2022/10/17 14:05
    * @param id
    * @param userName
    */
    @GetMapping("/updateAccount")
    public CommonResult updateAccount(Integer id, String userName){
        return CommonResult.ok(userProtalService.updateAccount(id,userName));
    }

    /**
    * @Author hbx
    * @Description 修改用户昵称信息
    * @Date 2022/10/17 14:40
    * @param id
    * @param nickName
    */
    @GetMapping("/updateNickName")
    public CommonResult updateNickName(Integer id, String nickName){
        return CommonResult.ok(userProtalService.updateNickName(id,nickName));
    }

    /**
    * @Author hbx
    * @Description 修改用户自我介绍
    * @Date 2022/10/17 14:50
    * @param id
    * @param introduction
    */
    @GetMapping("/updateIntroduction")
    public CommonResult updateIntroduction(Integer id, String introduction){
        return CommonResult.ok(userProtalService.updateIntroduction(id,introduction));
    }


    /**
    * @Author cjl
    * @Description 审核骑手成功 发送邮箱提示
    * @Date  8:50
    * @Return com.bgs.eat.config.CommonResult
    * @param userProtalEntity
    */
    @PutMapping("/updateHorsemanauDitIdSucceed")
    CommonResult updateHorsemanauDitIdSucceed(UserProtalEntity userProtalEntity){
        int i = userProtalService.updateHorsemanauDitIdSucceed(userProtalEntity);
        return CommonResult.ok();
    }
    /**
    * @Author cjl
    * @Description 审核骑手失败 发送邮箱提示
    * @Date  10:11
    * @Return com.bgs.eat.config.CommonResult
    * @param map
    */
    @PutMapping("/updateHorsemanauDitIdFail")
    CommonResult updateHorsemanauDitIdFail(@RequestBody Map<String,String> map){
        int i = userProtalService.updateHorsemanauDitIdFail(map);
        return CommonResult.ok();
    }

    /**
    * @Author cjl
    * @Description 审核商家成功 发送邮箱提示
    * @Date  10:14
    * @Return com.bgs.eat.config.CommonResult
    * @param userProtalEntity
    */
    @PutMapping("/updateMerchantDitIdSucceed")
    CommonResult updateMerchantDitIdSucceed(UserProtalEntity userProtalEntity){
        int i = userProtalService.updateMerchantDitIdSucceed(userProtalEntity);
        return CommonResult.ok();
    }

    /**
    * @Author cjl
    * @Description 审核商家失败 发送邮箱提示
    * @Date  10:15
    * @Return com.bgs.eat.config.CommonResult
    * @param map
    */
    @PutMapping("/updateMerchantDitIdFail")
    CommonResult updateMerchantDitIdFail(@RequestBody Map<String,String> map){
        int i = userProtalService.updateMerchantDitIdFail(map);
        return CommonResult.ok();
    }

    /**
    * @Author cjl
    * @Description 删除审核的用户
    * @Date  11:25
    * @Return java.lang.Integer
    * @param id
    */
    @DeleteMapping("/deleteUserProtalById")
    Integer deleteUserBackEntityById(Integer id){
        return userProtalService.deleteUserProtalById(id);
    }


    /**
    * @Author hbx
    * @Description 修改用户头像
    * @Date 2022/10/18 8:30
    * @param file
    */
    @RequestMapping("/applyUploadImage")
    public CommonResult applyUploadImage(MultipartFile file){
        return userProtalService.applyUploadImage(file);
    }

    /**
    * @Author hbx
    * @Description 修改用户的头像 （前端）
    * @Date 2022/10/18 8:45
    * @param id
    * @param avatarId
    */
    @GetMapping("/updateAvatarId")
    public CommonResult updateAvatarId(Integer id, Integer avatarId){
        return CommonResult.ok(userProtalService.updateAvatarId(id,avatarId));
    }

    /**
    * @Author hbx
    * @Description 根据id查询用户信息
    * @Date 2022/10/18 15:21
    * @param id
    */
    @GetMapping("/getAllUserById")
    public CommonResult getAllUserById(Integer id){
        return CommonResult.ok(userProtalService.getAllUserById(id));
    }

    /**
    * @Author hbx
    * @Description 根据用户id修改手机号
    * @Date 2022/10/18 20:37
    * @param id
    * @param phone
    */
    @GetMapping("/updatePhoneById")
    public CommonResult updatePhoneById(Integer id, String phone){
        return CommonResult.ok(userProtalService.updatePhoneById(id,phone));
    }
    /**
    * @Author cjl
    * @Description 全查 前端用户（模糊查用户昵称）
    * @Date  10:51
    * @Return com.bgs.eat.page.PageResult
    * @param pageRequest
    * @param userName
    */
    @GetMapping("/getUserProtalByRoleOne")
    public PageResult getUserProtalByRoleOne(PageRequest pageRequest, String userName){
        return userProtalService.getUserProtalByRoleOne(pageRequest,userName);
    }
    
    /**
    * @Author cjl
    * @Description 全查 前端商家（模糊查用户昵称）
    * @Date  14:14
    * @Return com.bgs.eat.page.PageResult
    * @param pageRequest
    * @param userName
    */
    @GetMapping("/getUserProtalByRoleTwo")
    public PageResult getUserProtalByRoleTwo(PageRequest pageRequest, String userName){
        return userProtalService.getUserProtalByRoleTwo(pageRequest,userName);
    }

    /**
    * @Author cjl
    * @Description 全查 前端骑手（模糊查用户昵称）
    * @Date  14:15
    * @Return com.bgs.eat.page.PageResult
    * @param pageRequest
    * @param userName
    */
    @GetMapping("/getUserProtalByRoleThree")
    public PageResult getUserProtalByRoleThree(PageRequest pageRequest, String userName,Integer countyId, Integer roleId){
        return userProtalService.getUserProtalByRoleThree(pageRequest,userName,countyId,roleId);
    }

    /**
    * @Author cjl
    * @Description 修改 前端（用户，商家，骑手）
    * @Date  14:13
    * @Return com.bgs.eat.config.CommonResult
    * @param userProtalEntity
    */
    @PostMapping("/updateUserProtalEntity")
    CommonResult updateUserProtalEntity(UserProtalEntity userProtalEntity){
        int i = userProtalService.updateUserProtalEntity(userProtalEntity);
        return CommonResult.ok("恭喜你，操作成功！");
    }

}
